import 'package:flutter/material.dart';
import '../../l10n/app_localizations.dart';

class ConfirmPriceView extends StatefulWidget {
  final double discount;
  final double balance;
  final String symbol;
  final double originalPrice;
  final double processFee;
  
  const ConfirmPriceView({
    Key? key,
    required this.discount,
    required this.balance,
    required this.symbol,
    required this.originalPrice,
    required this.processFee,
  }) : super(key: key);

  @override
  _ConfirmPriceViewState createState() => _ConfirmPriceViewState();
}

class _ConfirmPriceViewState extends State<ConfirmPriceView> {
  bool _showDiscount = false;
  bool _showBalance = false;
  
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(15),
      padding: EdgeInsets.all(15),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
      ),
      child: Column(
        children: [
          _buildPriceRow(
            AppLocalizations.of(context)!.originalPrice,
            widget.symbol + widget.originalPrice.toStringAsFixed(2),
            Colors.black,
            false,
          ),

          if (_showDiscount) ...[
            SizedBox(height: 15),
            _buildPriceRow(
              AppLocalizations.of(context)!.discountDeduction,
              '-' + widget.symbol + widget.discount.toStringAsFixed(2),
              Colors.red,
              false,
            ),
          ],
          if (_showBalance) ...[
            SizedBox(height: 15),
            _buildPriceRow(
              AppLocalizations.of(context)!.balanceDeduction,
              '-' + widget.symbol + widget.balance.toStringAsFixed(2),
              Colors.red,
              false,
            ),
          ],
          SizedBox(height: 15),
          _buildPriceRow(
            AppLocalizations.of(context)!.handlingFee,
            widget.symbol + widget.processFee.toStringAsFixed(2),
            Colors.red,
            false,
          ),
        ],
      ),
    );
  }
  
  Widget _buildPriceRow(String title, String value, Color color, bool isBold) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          title,
          style: TextStyle(
            color: Colors.black,
            fontSize: 15,
          ),
        ),
        Text(
          value,
          style: TextStyle(
            color: color,
            fontSize: 15,
            fontWeight: isBold ? FontWeight.bold : FontWeight.normal,
          ),
        ),
      ],
    );
  }
  
  @override
  void didUpdateWidget(covariant ConfirmPriceView oldWidget) {
    super.didUpdateWidget(oldWidget);
    setState(() {
      _showDiscount = widget.discount > 0;
      _showBalance = widget.balance > 0;
    });
  }
}